package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.entity.ChargeRecordEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface IChargeRecordMapper extends BaseMapper<ChargeRecordEntity> {

    @Select("SELECT * FROM t_charge_record WHERE u_userRef = #{userRef} ORDER BY u_totalMoney DESC LIMIT 1;")
    @ResultMap("findNewChargeRecordMap")
    ChargeRecordEntity findNewChargeRecord(@Param("userRef")long userRef );


    @Select("SELECT t1.* " +
            "FROM t_charge_record t1" +
            "  INNER JOIN (" +
            "  SELECT u_userRef, MAX(u_totalMoney) AS max_totalMoney" +
            "  FROM t_charge_record" +
            "  GROUP BY u_userRef" +
            ") t2 ON t1.u_userRef = t2.u_userRef AND t1.u_totalMoney = t2.max_totalMoney;")
    @ResultMap("findUserTotalChargeRecordMap")
   List<ChargeRecordEntity> findUserTotalChargeRecord();


}
